package com.example.demo2.config;

//import com.example.demo2.config.interceptor.JwtInterceptor;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//
//@Configuration
//public class InterceptorConfig implements WebMvcConfigurer {
//    @Override
//    public void addInterceptors(InterceptorRegistry interceptorRegistry){
//        interceptorRegistry.addInterceptor(jwtInterceptor())
//                .addPathPatterns("/*")
//                .excludePathPatterns("/admin/login");
//    }
//    @Bean
//    public JwtInterceptor jwtInterceptor(){
//        return new JwtInterceptor();
//    }
//}
import com.example.demo2.config.interceptor.JwtInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements  WebMvcConfigurer {

    @Autowired
    JwtInterceptor jwtInterceptor;

//    @Override
//    public void configurePathMatch(PathMatchConfigurer configurer) {
//        // 指定controller统一的接口前缀
//        configurer.addPathPrefix("/api", clazz -> clazz.isAnnotationPresent(RestController.class));
//    }

    // 加自定义拦截器JwtInterceptor，设置拦截规则
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(jwtInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/admin/login","/swagger-ui/**","/files/**","/order/echart");
    }
}
